﻿using CoachingOrganizer.Logic.Common;
using CoachingOrganizer.Logic.Models.Tools.MoneyCalculation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CoachingOrganizer.Logic.Logic.Tools.MoneyCalculation
{
    internal class PeriodStableGroupReportLogic : PeriodGroupReportLogicBase
    {
        private readonly PeriodStableGroupReportModel _model;
        private readonly IEnumerable<StableMoneyFlowItemLogic> _items;

        public PeriodStableGroupReportModel Model
        {
            get { return _model; }
        }

        public PeriodStableGroupReportLogic(string name, int sign, IEnumerable<StableMoneyFlowItemLogic> items, LogicExtender logicExtender, PeriodReportLogic upperLogic)
            : this(new PeriodStableGroupReportModel(name, sign, items.Select(l => l.Model)), logicExtender, upperLogic, items)
        {

        }

        public PeriodStableGroupReportLogic(PeriodStableGroupReportModel model, LogicExtender logicExtender, PeriodReportLogic upperLogic, IEnumerable<StableMoneyFlowItemLogic> items)
            : base(model, logicExtender, upperLogic)
        {
            _model = model;
            _items = items;
        }

        public override decimal GetAmount()
        {
            return _items.Select(i => i.GetPeriodAmount(_upperLogic.Model.StartDate, _upperLogic.Model.FinishDate)).Sum();
        }
    }
}
